<?php
//模型
class CurrencyModel extends MY_Model {
	function __construct(){
		parent::__construct();
		$this->table = 'currencys';
	}
	
	function get_list($arr=array(),$page=1,$size=10){
		$where = ' 1 ';
		
		if(isset($arr['name']) && !empty($arr['name'])){
			$where .= " AND name='{$arr['name']}' ";
		}
		
		$res = $this->_where_get_list($where,$page,$size,'order by addtime desc');
		
		return $res;
	}
	
	function get_info($id){
		$sql  = "select * from ".$this->db->dbprefix.$this->table." where id='{$id}' limit 1";
		$query = $this->db->query($sql);
		$row = $query->row_array();
		return $row;
	}
	
	function get_all(){
		$sql  = "select name from ".$this->db->dbprefix.$this->table." where 1 GROUP BY name ";
		$query = $this->db->query($sql);
		$ls_res = $query->result_array();

		$arr = array();
		foreach($ls_res as $val){
			$sql  = "select * from ".$this->db->dbprefix.$this->table." where name='{$val['name']}' ORDER BY addtime DESC limit 1";
			$query = $this->db->query($sql);
			$row = $query->row_array();
			
			$arr[] = $row;
		}
		return $arr;
		
	}
	
	function bz_get_info($bz){
		$list = $this->get_all();
		foreach($list as $val){
			if($bz==$val['name']){
				return $val;
			}
		}
		return false;
	}
	
	function date_get_list($date){
		
		$where = " FROM_UNIXTIME(addtime,'%Y-%m-%d')='{$date}' ";
		$sql  = "select * from ".$this->db->dbprefix.$this->table." where {$where} GROUP BY name ";
		
		$query = $this->db->query($sql);
		$ls_res = $query->result_array();
		
		return $ls_res;
	}

	//只获取固定的美元和港币
	function get_fixed_coin(){
		$sql = "select * from ".$this->db->dbprefix.$this->table." where name='美元' or name='港币' GROUP BY name order by id desc";

		$query = $this->db->query($sql);
		$ls_res = $query->result_array();
		
		return $ls_res;
	}
}

